<?php
$this->headTitle('Tra cứu thông tin username '.$this->gameCheck['gameName'].' ('.$this->gameCheck['gameId'].')', 'append');
?>

<div class="grid">
    <div class="breadcrumbs">
        <a class="item-1 loading" href="/index">Trang chủ CI</a> › 
        <a class="item-2 loading" href="/userinfo/index/game/<?php echo $this->gameCheck['gameId'];?>"><?php echo $this->gameCheck['gameName'],' (',$this->gameCheck['gameId'],')';?></a> › 
        <span class="blue">Tra cứu thông tin username</span>
        <div class="clear-both"></div>
    </div>
    <?php if(isset($this->repair)){ ?>
            <?php
                if($this->flag == 'success')
                    echo '<div class="notification success">',$this->mess,'</div>';
                elseif($this->flag == 'alert')
                    echo '<div class="notification alert">',$this->mess,'</div>';
                else
                    echo '<div class="notification error">',$this->mess,'</div>';
            ?>
    <?php }else{ ?>
    <div class="flugin">
        <div class="search">
            <div class="form">
                <div id="tabs-search">
                    <ul class="tabs-menu">
                        <li class="active" id="tabs-1"><span>Tìm kiếm</span></li>
                    </ul>
                    <div class="tabs tabs-1">
                        <form name="fSeachDate" action="/userinfo/index/game/<?php echo $this->gameCheck['gameId'];?>" method="GET"onsubmit="return checkSearchTransaction();">
                            <div class="name">
                                <label>Nhân vật</label>
                                <input type="text" name="username" value="<?php echo (isset($this->username)) ? $this->username : '';?>"/>
                            </div>
                            <?php $arrGameId=array('ss31', 'ss32');
                                 if(!in_array($this->gameCheck['gameId'], $arrGameId)){ 
                            ?>
                            <div class="type" style="width: auto; clear: both;;">
								<label>Channel</label>
                                <select name="channel" class="channel" style="width: 120px;float: left;">
                                    <option value="0">Vui lòng chọn</option>
                                    <?php 
                                        $listChannel = '';
                                        foreach($this->arrChannel as $key=>$channel){
                                            echo '<option value="',$key,'"',(isset($this->channel) && $this->channel == $key) ? 'selected="selected"' : '','>',$channel['name'],'</option>';
                                            $listChannel .= " {$key}";
                                        } 
                                    ?>
                                </select>
                                
								<div class="server" style="float: left; margin: 0 0 0 15px;">
                                    <label>Server</label>
                                    <select name="serverId" class="serverId" style="width: 150px;">
                                        <?php
                                            echo '<option class="0" value="0">Tất cả</option>';
                                            if(isset($this->arrServer) && is_array($this->arrServer)){
                                                foreach($this->arrServer as $key=>$server){
                                                    echo '<option value="',$key,'"',(isset($this->serverId) && $this->serverId == $key) ? 'selected="selected"' : '','>',$server,'</option>';
                                                }
                                            }
                                        ?>
                                    </select>
                                    <select name="serverList" class="serverList hidden">
                                        <option value="0">Vui lòng chọn Channel</option>
                                        <option class="<?php echo trim($listChannel);?> 0" value="0">Tất cả</option>
                                        <?php 
                                            foreach($this->arrServer as $key=>$row){
                                                $cls = '';
                                                foreach($this->arrChannel as $key2=>$channel){
                                                    if(in_array($key, $channel['value'])){
                                                        $cls .= ' '.$key2;
                                                    }
                                                }
                                                (strlen($cls) > 0) ? $cls = trim($cls) : $cls = '';
                                                echo '<option value="',$key,'" class="0 ',$cls,'">',$row,'</option>';
                                            } 
                                        ?>
                                    </select>
									
                                    <div class="clear-both"></div>
                                </div>
                            </div>
                            <?php } ?>
                            <div class="submit">
                                <input type="submit" name="bntSubmit" value="Tìm" class="loading"/>
                            </div>
                            <div class="clear-both"></div>
                        </form>
                    </div>
                    <div class="clear-both"></div>
                </div>
                <div class="clear-both"></div>
            </div>
            <div class="clear-both"></div>
            <script type="text/javascript">
                function checkSearchTransaction(){
                    var username = document.fSeachDate.username.value;
                    if (username==null || username=="")
                    {
                        alert("Vui lòng nhập username!");
                        $('.loading-please-wait').css('display','none');
                        return false;
                    }
                    /*
                    var serverId = document.fSeachDate.serverId.value;
                    if (serverId==null || serverId=="" || serverId=="0")
                    {
                        alert("Vui lòng nhập serverId!");
                        $('.loading-please-wait').css('display','none');
                        return false;
                    }
                    */
                    return true;
                }
                $(document).ready(function(){
                    /*
                    $(".channel").change(function() {
                        val = $(this).find("option:selected").val();
                        $(".serverId option").remove();
                        $(".serverList option."+val).clone().appendTo(".serverId");
                    });
                    */
                    $(".channel").change(function() {
                        val = $(this).find("option:selected").val();
                        $(this).parent().find(".serverId option").remove();
                        $(this).parent().find(".serverList option."+val).clone().appendTo(".serverId");
                    });
                })
            </script>
        </div>
        <?php
            if($this->mess){
                if($this->flag == 'success')
                    echo '<div class="notification success">',$this->mess,'</div>';
                elseif($this->flag == 'alert')
                    echo '<div class="notification alert">',$this->mess,'</div>';
                else
                    echo '<div class="notification error">',$this->mess,'</div>';
            }
        ?>
        <?php 
        if($this->dataUser){
            if($this->gameCheck['gameId']!='ss31')
            {
        ?>
        <div class="table">
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                <thead>
                    <tr>
                        <td class="column">STT</td>
                        <td class="column">Channel</td>
                        <td class="column">ServerID</td>
                       <?php
                        $arrKey=array();
                          foreach($this->title as $key=>$val){
                            if(isset($this->dataRoleTitle[$key])) {
                                 $arrKey[]=$key;
                                 echo '<td class="column">',$val ,'</td>';
                            }
                        }
                        
                        ?>
                        <td class="column">Username</td>
                    </tr>
                </thead>
                <tbody>
                    <?php 
                        $stt = 1;
            
                        foreach($this->dataUser as $key=>$row){
                            $serverName = (isset($this->arrServer[$key])) ? $this->arrServer[$key] : $key;
                            foreach($row as $user){
                                if($this->dataUsername){
                                    foreach($this->dataUsername as $key2 => $row2){
                                        if(!isset($row2[$user['username']])){
                                            continue;
                                        }
                                        echo '<tr>';
                                        echo '<td class="text-align-center">',$stt,'</td>';
                                        echo '<td class="text-align-center">',$key2,'</td>';
                                        echo '<td class="text-align-left">',$serverName,'</td>';
                                        foreach($arrKey as $val){
                                    	   echo '<td class="text-align-left">',$user[$val],'</td>';
                                        }
                                        echo '<td class="text-align-left">',$row2[$user['username']],'</td>';
        								echo '</tr>';
                                        ++$stt; 
                                    }
                                }else{
                                    echo '<tr>';
                                    echo '<td class="text-align-center">',$stt,'</td>';
                                    echo '<td class="text-align-center">',$key2,'</td>';
                                    echo '<td class="text-align-left">',$serverName,'</td>';
                                    foreach($arrKey as $val){
                                	   echo '<td class="text-align-left">',$user[$val],'</td>';
                                    }
                              	    echo '<td class="text-align-left">',$row2[$user['username']],'</td>';
    								echo '</tr>';
                                    ++$stt; 
                                }
                            }
                        }
                    ?>
                </tbody>
            </table>
        </div>
        <?php } else {//else game ss31
          ?>      
            <div class="table">
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                <thead>
                    <tr>
                        <td class="column">STT</td>
                        <td class="column">UserName</td>
                        <?php
                        $arrKey=array();
                          foreach($this->title as $key=>$val){
                            if(isset($this->dataRole[$key])) {
                                 $arrKey[]=$key;
                                 echo '<td class="column">',$val ,'</td>';
                            }
                        }
                        ?>
                    </tr>
                </thead>
                <tbody>
                    <?php 
                        $stt = 1;
                        echo '<tr>';
                        echo '<td class="text-align-center">',$stt,'</td>';
                        echo '<td class="text-align-center">',$this->dataUser['username'],'</td>';
                        foreach($arrKey as $row)
                        {
                             if($row=='roleAllLevel')
                             {?>
                                <td class="text-align-left">
                                <?php foreach($this->dataRole['roleAllLevel'] as $key => $value){
                                    foreach($this->listGame as $keyGame => $valGame){
                                    if($value['gameId']==$keyGame){
                                        echo $valGame,'<span style="color:red; font-weight:bold;"> _Level ',$value['level'], '</span></br>';
                                    }
                                }
                            }?>
                                </td><?php }
                             else{
                                echo '<td class="text-align-left">',$this->dataRole[$row],'</td>';
                             }
                        }
                        echo '</tr>'; 
                     
                              
                        
                    ?>
                </tbody>
            </table>
        </div>
            <?php }//end else ss31
        } ?>
    </div>
    <?php } ?>
</div>
